home *** CD-ROM | disk | FTP | other *** search
- Path: news.cuny.edu!x60cc
- From: SHAHZAD ANJUM MALIK <X60CC@CUNYVM.CUNY.EDU>
- Newsgroups: comp.lang.c
- Subject: A Linked List Problem
- Date: Thu, 22 Feb 1996 01:51:13 EST
- Message-ID: <96053.015114X60CC@CUNYVM.CUNY.EDU>
- NNTP-Posting-Host: cunyvm.cuny.edu
- Disclaimer: Author bears full responsibility for this post
-
- Hi!
- I am trying to create a small program using Linked Lists. Actually, I
- am planning to use Linked Lists in Linked Lists. A simple application of the
- program would be to add a customer name etc and then add a magazine to be
- subscribed to the customer, and if the customer wants add a 2nd and 3rd and
- so on. For adding new customers I am using Linked Lists of nested structures.
- Structures look like this:
-
- struct CustName
- {
- char LastName[15];
- char ID#[5];
- };
- struct Magazine
- {
- char MagName[20];
- struct Magazine *nextMag;
- };
- struct CustProfile
- {
- struct CustName Name;
- struct Magazine Mag;
- struct CustProfile *next;
- };
- typedef struct CustProfile ELEMENT;
- typedef ELEMENT *LINK;
-
-
-
- main()
- {
- LINK current, head;
- head = NULL;
- NewNode = (LINK)malloc(sizeof(ELEMENT));
- if(head == NULL)
- head = current = NewNode;
- else
- {
- current = head;
- while (current->next ! = NULL)
- current = current->next;
- current->next = NewNode;
- current = NewNode;
- }
-
- printf("Enter Customer Name: ");
- gets(current->Name.LastName);
- printf("Enter Mag Name");
- gets(current->Mag.MagName);
- printf("Enter Second Mag Name");
- gets(current->Mag.nextMag->MagName);
-
- current->Mag = current->Mag.nextMag;
- current->next = NULL;
- }
-
-
- The problem is that the complier (MSC 6.00) gives syntax error on the
- 2nd last line. I have been trying to remove the mistake for several
- days but useless. The error for "current->Mag = current->Mag.nextMag"
- is " Erro No. '=' incompatible types. I will be extremely grateful if
- someone could help me in either removing the error or giving me a simpler
- idea of implementing the same code in a different way. My problem is
- that I want to use LinkedLists and not arrays. Also I want to use Linked
- Lists in Linked Lists. In the above program, I uesd Magazine structure
- which has a pointer field to the next Magazine structure. Similarly
- the main structure CustProfile also has a pointer pointing to the next
- structure.
-
- I'll really appreciate if someone please send a solution at the earliest
- possible. Thank you.
-